<?php

namespace Sffi\ElementPlus\ElForm;

/**
 * 富文本
 */
class ElRichText extends FormItem
{
    protected string $type = 'richtext';
    protected string $placeholder;
    protected string $saveType = 'local';
    protected static array $saveTypes = ['local', 'alioss'];
    protected string $url;
    protected array $enableToolbar;
    protected array $disableToolbar;

    public function __construct($title, $key, $placeholder='请输入')
    {
        $this->title = $title;
        $this->key = $key;
        $this->prop = $key;
        $this->placeholder = $placeholder;
    }
    
    /**
     * 设置保存方式
     * @param string $saveType local 本地  alioss 阿里云
     * @return $this
     */
    public function setSaveType(string $saveType = 'local', $localUrl = ''){
        if  (in_array($saveType, self::$saveTypes)) {
            $this->saveType = $saveType;
            $this->url = $localUrl;
            return $this;
        }
        throw new \Exception('保存方式错误');
    }

    /**
     * 设置可用工具栏
     *  @param array $enableToolbar 工具栏 [
     *      "bold","underline","italic","through","code","sub","sup","clearStyle","color","bgColor","fontSize","fontFamily","indent","delIndent","justifyLeft",
     *      "justifyRight","justifyCenter","justifyJustify","lineHeight","insertImage","deleteImage","editImage","viewImageLink","imageWidth30","imageWidth50",
     *      "imageWidth100","divider","emotion","insertLink","editLink","unLink","viewLink","codeBlock","blockquote","headerSelect","header1","header2","header3",
     *      "header4","header5","todo","redo","undo","fullScreen","enter","bulletedList","numberedList","insertTable","deleteTable",
     *      "insertTableRow","deleteTableRow","insertTableCol","deleteTableCol","tableHeader","tableFullWidth","insertVideo","uploadVideo","editVideoSize",
     *      "uploadImage","codeSelectLang"]
     */
    public function setEnableToolbar(array $enableToolbar) {
        $this->enableToolbar = $enableToolbar;
        return $this;
    }

    /**
     * 设置不可用的工具栏
     *  @param array $disableToolbar 工具栏 "bold"|"underline"|"italic"|"through"|"code"|"sub"|"sup"|"clearStyle"|"color"|"bgColor"|"fontSize"|"fontFamily"|"indent"|"delIndent"|"justifyLeft"|"justifyRight"|"justifyCenter"|"justifyJustify"|"lineHeight"|"insertImage"|"deleteImage"|"editImage"|"viewImageLink"|"imageWidth30"|"imageWidth50"|"imageWidth100"|"divider"|"emotion"|"insertLink"|"editLink"|"unLink"|"viewLink"|"codeBlock"|"blockquote"|"headerSelect"|"header1"|"header2"|"header3"|"header4|"header5|"todo|"redo|"undo|"fullScreen|"enter|"bulletedList|"numberedList|"insertTable|"deleteTable|"insertTableRow|"deleteTableRow|"insertTableCol|"deleteTableCol|"tableHeader"|"tableFullWidth"|"insertVideo"|"uploadVideo"|"editVideoSize"bold"|"underline"|"italic"|"through"|"code"|"sub"|"sup"|"clearStyle"|"color"|"bgColor"|"fontSize"|"fontFamily"|"indent"|"delIndent"|"justifyLeft"|"justifyRight"|"justifyCenter"|"justifyJustify"|"lineHeight"|"insertImage"|"deleteImage"|"editImage"|"viewImageLink"|"imageWidth30"|"imageWidth50"|"imageWidth100"|"divider"|"emotion"|"insertLink"|"editLink"|"unLink"|"viewLink"|"codeBlock"|"blockquote"|"headerSelect"|"header1"|"header2"|"header3"|"header4|"header5|"todo|"redo|"undo|"fullScreen|"enter|"bulletedList|"numberedList|"insertTable|"deleteTable|"insertTableRow|"deleteTableRow|"insertTableCol|"deleteTableCol|"tableHeader"|"tableFullWidth"|"insertVideo"|"uploadVideo"|"editVideoSize"|"uploadImage"|"codeSelectLang"|"uploadImage"|"codeSelectLang"
     */
    public function setDisableToolbar(array $disableToolbar) {
        $this->disableToolbar = $disableToolbar;
        return $this;
    }
}